package com.kyle.silverbullet.client.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

/**
 * 假设搭建好了是可以访问这个HelloWorld资源
 */
@RestController
@RequestMapping("/api")
public class ApiController {
    /**
     * 没有认证情况下：
     * {
     * "timestamp": "2020-06-23 16:05:00",
     * "status": 403,
     * "error": "Forbidden",
     * "message": "Access Denied",
     * "path": "/HelloWorld"
     * }
     * <p>
     * <p>
     * 想要通过认证，如果是password模式：
     * 1.首先要获得token
     * http://localhost:19098/oauth/token?username=user_1&password=123456&grant_type=password&scope=select&client_id=client_1&client_secret=123456
     * <p>
     * {
     * "access_token": "3b77c392-7bee-4c5c-a4e8-4b2b7d9b1532",
     * "token_type": "bearer",
     * "refresh_token": "df8e60f6-85f8-45cc-8183-f015ed2a239c",
     * "expires_in": 43199,
     * "scope": "select"
     * }
     * <p>
     * 2.将access_token放在请求头中，格式为
     * 键为 Authorization（从org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor可以知道）
     * 值为 Bearer 3b77c392-7bee-4c5c-a4e8-4b2b7d9b1532
     *
     * @return
     */
    @GetMapping("/HelloWorld")
    public String apiHelloWorld() {
        return "apiHelloWorld";
    }


    @GetMapping("/HelloWorld2")
    public Mono<String> apiHelloWorld2() {
        return Mono.just("apiHelloWorld");
    }
}
